package org.example.springkafka.Producer;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
public class TransactionProducer {
    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;
    @Transactional
    public void sendString() {
       for (int i = 0; i < 10; i++) {
           kafkaTemplate.send("test", String.valueOf(i),"hello world"+i);
           if(i == 6){
               throw new RuntimeException("fail");
           }
       }


    }
}
